package com.chilli.cosima.data.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.chilli.cosima.data.BaseHibernateDAO;
import com.chilli.cosima.data.bean.Customer;
import com.chilli.cosima.data.dao.CustomerDAO;

public class CustomerDAOImpl extends BaseHibernateDAO implements CustomerDAO
{

	public Long createCustomer(Customer customer)
	{
		return (Long) createObject(customer);
	}

	public void deleteCustomer(Long id)
	{
		deleteObject(getObjectById(Customer.class, id));
	}

	public Customer findCustomerById(Long id)
	{
		return (Customer) getObjectById(Customer.class, id);
	}

	@SuppressWarnings("unchecked")
	public Map findCustomerByPage(int current, int pageSize)
	{
		Map map = new HashMap();
		List list = findObjectByHQL(" from Customer", new String[]
		{}, current, pageSize);

		int count = findObjectByHQL("from Customer").size();

		map.put("count", count);
		map.put("list", list);
		return map;
	}

	@SuppressWarnings("unchecked")
	public Map findCustomerByPageAndQuery(int current, int pageSize,
			String customer)
	{
		Map map = new HashMap();
		List list = findObjectByHQL(" from Customer c where c.name like '%" + customer + "%'", new String[]
		{}, current, pageSize);

		int count = findObjectByHQL(" from Customer c where c.name like '%" + customer + "%'").size();

		map.put("count", count);
		map.put("list", list);
		return map;
	}

	public void updateCustomer(Customer customer)
	{
		updateObject(customer);
	}

}
